package com.tdkj.action.backstage.risevalue;

import javax.annotation.Resource;

import com.tdkj.action.BaseAction;
import com.tdkj.model.common.BeanType;
import com.tdkj.model.risevalue.BeanAdvert;
import com.tdkj.service.common.IBeanTypeService;
import com.tdkj.service.risevalue.IBeanAdvertService;


public class AdTemplateAction extends BaseAction {
	private String name;//广告位名称
	private String code;//广告位编号
	private Long pageid;//对应页面id
	private String pagename;//对应页面名称
	private String pagecode;//对应页面编号
	private String pagetype;//对应页面类型
	private BeanType bean;
	private String codes;
	private String message;
	private IBeanTypeService beanService;
	private IBeanAdvertService advertService;
	public Long getPageid() {
		return pageid;
	}
	public void setPageid(Long pageid) {
		this.pageid = pageid;
	}
	public String getPagename() {
		return pagename;
	}
	public void setPagename(String pagename) {
		this.pagename = pagename;
	}
	public String getPagecode() {
		return pagecode;
	}
	public void setPagecode(String pagecode) {
		this.pagecode = pagecode;
	}
	public String getPagetype() {
		return pagetype;
	}
	public void setPagetype(String pagetype) {
		this.pagetype = pagetype;
	}
	public String getCodes() {
		return codes;
	}
	public void setCodes(String codes) {
		this.codes = codes;
	}
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	public BeanType getBean() {
		return bean;
	}

	public void setBean(BeanType bean) {
		this.bean = bean;
	}

	public IBeanTypeService getBeanService() {
		return beanService;
	}

	@Resource
	public void setBeanService(IBeanTypeService beanService) {
		this.beanService = beanService;
	}
	
	public IBeanAdvertService getAdvertService() {
		return advertService;
	}
	@Resource
	public void setAdvertService(IBeanAdvertService advertService) {
		this.advertService = advertService;
	}
	public String findAll(){
		return "findAll";
	}
	public String findRightPage(){
		if(this.getPageid()!=null){
			bean=beanService.findById(this.getPageid(), BeanType.class);
			if(bean.getProp().get("type")==null){
				BeanType b=new BeanType();
				b.setName("网站首页");
				bean=beanService.findByExample(b).get(0);
			}
		}else{
			BeanType b=new BeanType();
			b.setName("网站首页");
			bean=beanService.findByExample(b).get(0);
		}
		return findTemplatePage(bean.getProp().get("type"),bean.getProp().get("code"));
	}
	public String addAdvert(){
		bean=beanService.findById(this.getPageid(), BeanType.class);
		String[] c=this.getCodes().split("#");
		if (null != c) {
			for (String code : c) {
				BeanAdvert t=new BeanAdvert();
				t.setCode(code);
				t.setName(code);
				t.setWidth(200);
				t.setHeight(200);
				t.setPageid(bean.getId());
				t.setPagename(bean.getName());
				t.setPagecode(bean.getProp().get("code"));
				t.setPagetype(bean.getProp().get("type"));
				t.setStatus("空闲");
				//t.setFileurl(ADFileUtil.findAD(code));
				advertService.save(t);
			}
		}
		this.setMessage("添加成功");
		return "add";
	}
	private String findTemplatePage(String t,String c){
		if(t.equals("index")){
			return "t_index";
		}
		if(t.equals("sindex")){
			return "t_sindex";
		}
		if(t.equals("md")){
			if(c.equals("1")){
				
			}else{
				return "t_md";
			}
		}
		if(t.equals("cl")){
			if(c.equals("1")){
				
			}else{
				return "t_cl";
			}
		}
		if(t.equals("co")){
			if(c.equals("1")){
						
			}else{
				return "t_co";
			}
		}
		return "";
	}
}
